



    <template>
    <div :style="{margin: '0 auto',width:'100%'}">
    <el-row :gutter="15" class="">
    <el-form ref="formRef" :model="dataForm" :rules="dataRule" size="default" label-width="100px" label-position="right"  :disabled="setting.readonly" >
    <template v-if="!loading && formOperates">
        <!-- 具体表单 -->
        <el-col :span="24"  v-if="judgeShow('projectS')" >
        <jnpf-form-tip-item
 label="所属项目"  v-if="judgeShow('projectS')"              align=""
fixed="${config.tableFixed}"  prop="projectS" >
        <JnpfSelect   v-model="dataForm.projectS" @change="changeData('projectS',-1)" 
 placeholder="请选择"  :disabled="judgeWrite('projectS')"  clearable  :style='{"width":"100%"}' :filterable = 'false'  :options="projectSOptions" :props="projectSProps" >
    </JnpfSelect>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="12"  v-if="judgeShow('depNameA')" >
        <jnpf-form-tip-item
 label="所属部门"  v-if="judgeShow('depNameA')"              align=""
fixed="${config.tableFixed}"  prop="depNameA" >
        <JnpfDepSelect   v-model="dataForm.depNameA" @change="changeData('depNameA',-1)" 
 placeholder="请选择"  selectType="all"  :ableIds="ableAll.depNameAableIds"  :disabled="judgeWrite('depNameA')"  clearable  :style='{"width":"100%"}' :filterable = 'false' >
    </JnpfDepSelect>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="12"  v-if="judgeShow('applys')" >
        <jnpf-form-tip-item
 label="填单人"  v-if="judgeShow('applys')"              align=""
fixed="${config.tableFixed}"  prop="applys" >
        <JnpfUserSelect   v-model="dataForm.applys" @change="changeData('applys',-1)" 
 placeholder="请选择"  selectType="all"  :ableIds="ableAll.applysableIds"  :disabled="judgeWrite('applys')"  clearable  :style='{"width":"100%"}'>
    </JnpfUserSelect>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="24"  v-if="judgeShow('contractor')" >
        <jnpf-form-tip-item
 label="承包方"  v-if="judgeShow('contractor')"              align=""
fixed="${config.tableFixed}"  prop="contractor" >
        <JnpfInput   v-model="dataForm.contractor" @change="changeData('contractor',-1)" 
 placeholder="请输入"  :disabled="judgeWrite('contractor')"  clearable  :style='{"width":"100%"}'>
    </JnpfInput>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="12"  v-if="judgeShow('firstparty')" >
        <jnpf-form-tip-item
 label="客户名称"  v-if="judgeShow('firstparty')"              align=""
fixed="${config.tableFixed}"  prop="firstparty" >
        <JnpfInput   v-model="dataForm.firstparty" @change="changeData('firstparty',-1)" 
 placeholder="请输入"  :disabled="judgeWrite('firstparty')"  clearable  :style='{"width":"100%"}'>
    </JnpfInput>
    </jnpf-form-tip-item>
        </el-col>

        <el-col :span="12"  v-if="judgeShow('arrivalDate')" >
        <jnpf-form-tip-item
 label="填单日期"  v-if="judgeShow('arrivalDate')"              align=""
fixed="${config.tableFixed}"  prop="arrivalDate" >
        <JnpfDatePicker   v-model="dataForm.arrivalDate" @change="changeData('arrivalDate',-1)" 
 :startTime="dateTime(false,1,1,'','')"  :endTime="dateTime(false,1,1,'','')"  placeholder="请选择"  :disabled="judgeWrite('arrivalDate')"  clearable  :style='{"width":"100%"}' format="yyyy-MM-dd" >
    </JnpfDatePicker>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="24"  v-if="judgeShow('signer')" >
        <jnpf-form-tip-item
 label="合同签订人"  v-if="judgeShow('signer')"              align=""
fixed="${config.tableFixed}"  prop="signer" >
        <JnpfInput   v-model="dataForm.signer" @change="changeData('signer',-1)" 
 placeholder="请输入"  :disabled="judgeWrite('signer')"  clearable  :style='{"width":"100%"}'>
    </JnpfInput>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="12"  v-if="judgeShow('contractNumber')" >
        <jnpf-form-tip-item
 label="合同编号"  v-if="judgeShow('contractNumber')"              align=""
fixed="${config.tableFixed}"  prop="contractNumber" >
        <JnpfInput   v-model="dataForm.contractNumber" @change="changeData('contractNumber',-1)" 
 placeholder="系统自动生成"  :disabled="judgeWrite('contractNumber')"  readonly  :style='{"width":"100%"}'>
    </JnpfInput>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="12"  v-if="judgeShow('contract')" >
        <jnpf-form-tip-item
 label="合同"  v-if="judgeShow('contract')"              align=""
fixed="${config.tableFixed}"  prop="contract" >
        <JnpfInput   v-model="dataForm.contract" @change="changeData('contract',-1)" 
 placeholder="请输入"  :disabled="judgeWrite('contract')"  clearable  :style='{"width":"100%"}'>
    </JnpfInput>
    </jnpf-form-tip-item>
        </el-col>

        <el-col :span="14"  v-if="judgeShow('contractDate')" >
        <jnpf-form-tip-item
 label="合同签订日期"  v-if="judgeShow('contractDate')"              align=""
fixed="${config.tableFixed}"  prop="contractDate" >
        <JnpfDatePicker   v-model="dataForm.contractDate" @change="changeData('contractDate',-1)" 
 :startTime="dateTime(false,1,1,'','')"  :endTime="dateTime(false,1,1,'','')"  placeholder="请选择"  :disabled="judgeWrite('contractDate')"  clearable  :style='{"width":"100%"}' format="yyyy-MM-dd" >
    </JnpfDatePicker>
    </jnpf-form-tip-item>
        </el-col>

        <el-col :span="12"  v-if="judgeShow('startDateAa')" >
        <jnpf-form-tip-item
 label="开始日期"  v-if="judgeShow('startDateAa')"              align=""
fixed="${config.tableFixed}"  prop="startDateAa" >
        <JnpfDatePicker   v-model="dataForm.startDateAa" @change="changeData('startDateAa',-1)" 
 :startTime="dateTime(false,1,1,'','')"  :endTime="dateTime(false,1,1,'','')"  placeholder="年-月-日"  :disabled="judgeWrite('startDateAa')"  clearable  :style='{"width":"100%"}' format="yyyy-MM-dd" >
    </JnpfDatePicker>
    </jnpf-form-tip-item>
        </el-col>

        <el-col :span="12"  v-if="judgeShow('enddateQp')" >
        <jnpf-form-tip-item
 label="结束日期"  v-if="judgeShow('enddateQp')"              align=""
fixed="${config.tableFixed}"  prop="enddateQp" >
        <JnpfDatePicker   v-model="dataForm.enddateQp" @change="changeData('enddateQp',-1)" 
 :startTime="dateTime(false,1,1,'','')"  :endTime="dateTime(false,1,1,'','')"  placeholder="年-月-日"  :disabled="judgeWrite('enddateQp')"  clearable  :style='{"width":"100%"}' format="yyyy-MM-dd" >
    </JnpfDatePicker>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="24"  v-if="judgeShow('fujian')" >
        <jnpf-form-tip-item
 label="附件"  v-if="judgeShow('fujian')"              align=""
fixed="${config.tableFixed}"  prop="fujian" >
        <JnpfUploadFile   v-model="dataForm.fujian" @change="changeData('fujian',-1)" 
 :disabled="judgeWrite('fujian')"  tipText="只能上传不超过5MB的文件"  :fileSize="5" sizeUnit="MB"  :limit="9"  pathType="defaultPath"  :isAccount="0"  buttonText="点击上传" >
    </JnpfUploadFile>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="12"  v-if="judgeShow('contractMoney')" >
        <jnpf-form-tip-item
 label="合同金额"  v-if="judgeShow('contractMoney')"              align=""
fixed="${config.tableFixed}"  prop="contractMoney" >
        <JnpfInputNumber   v-model="dataForm.contractMoney" @change="changeData('contractMoney',-1)" 
 placeholder="请输入"  :disabled="judgeWrite('contractMoney')"  isAmountChinese  thousands  :style='{"width":"100%"}' :step="1"  :controls="false" >
    </JnpfInputNumber>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="24"  v-if="judgeShow('remarks')" >
        <jnpf-form-tip-item
 label="备注"  v-if="judgeShow('remarks')"              align=""
fixed="${config.tableFixed}"  prop="remarks" >
        <JnpfTextarea   v-model="dataForm.remarks" @change="changeData('remarks',-1)" 
 placeholder="请输入"  :disabled="judgeWrite('remarks')"  clearable  :style='{"width":"100%"}' :autosize='{"minRows":4,"maxRows":4}' >
    </JnpfTextarea>
    </jnpf-form-tip-item>
        </el-col>
        <el-col :span="12"  v-if="judgeShow('invoiced')" >
        <jnpf-form-tip-item
 label="已付款金额"  v-if="judgeShow('invoiced')"              align=""
fixed="${config.tableFixed}"  prop="invoiced" >
        <JnpfInputNumber   v-model="dataForm.invoiced" @change="changeData('invoiced',-1)" 
 placeholder="请输入"  :disabled="judgeWrite('invoiced')"  :style='{"width":"100%"}' :step="1"  :controls="true" >
    </JnpfInputNumber>
    </jnpf-form-tip-item>
        </el-col>
        <!-- 表单结束 -->
    </template>
    <SelectDialog v-if="selectDialogVisible" :config="currTableConf" :formData="dataForm"
                  ref="selectDialog" @select="addForSelect" @close="selectDialogVisible=false"/>
    </el-form>
    </el-row>
    <UserBox v-if="userBoxVisible" ref="userBox" @submit="submit" />
    </div>
    </template>

<script>
    import request from '@/utils/request'
    import {mapGetters} from "vuex";
    import {getFormById} from '@/api/workFlow/FormDesign'
    import comMixin from '@/views/workFlow/workFlowForm/mixin';
    import { getDataInterfaceRes } from '@/api/systemData/dataInterface'
    import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
    import { getDefaultCurrentValueUserId } from '@/api/permission/user'
    import { getDefaultCurrentValueDepartmentId } from '@/api/permission/organize'
    import { getDateDay, getLaterData, getBeforeData, getBeforeTime, getLaterTime } from '@/components/Generator/utils/index.js'
    import { thousandsFormat } from "@/components/Generator/utils/index"
    import SelectDialog from '@/components/SelectDialog'

    export default {
        mixins: [comMixin],
        components: { SelectDialog },
        props: [],
        data() {
        return {
            dataFormSubmitType: 0,
            continueBtnLoading: false,
            index: 0,
            prevDis: false,
            nextDis: false,
            allList: [],
            visible: false,
            loading: false,
            btnLoading: false,
            formRef: 'formRef',
            setting:{},
            eventType: '',
            userBoxVisible:false,
            selectDialogVisible: false,
            currTableConf:{},
            dataValueAll:{},
            addTableConf:{
            },
            //可选范围默认值
            ableAll:{
            },
            tableRows:{
        },
            Vmodel:"",
            currVmodel:"",
            dataForm: {
                                    projectS : undefined,
                                depNameA : undefined,
                                applys : undefined,
                                contractor : undefined,
                                firstparty : undefined,
                                arrivalDate : undefined,
                                signer : undefined,
                                contractNumber : undefined,
                                contract : undefined,
                                contractDate : undefined,
                                startDateAa : undefined,
                                enddateQp : undefined,
                                    fujian : [],
                                contractMoney : undefined,
                                remarks : undefined,
                                invoiced : undefined,
            },
            tableRequiredData: {},
            dataRule:
            {
            },
                            projectSOptions:[{"fullName":"选项一","id":"1"},{"fullName":"选项二","id":"2"}],
                            projectSProps:{"label":"fullName","value":"id"  },
            childIndex:-1,
            interfaceRes: {
                        projectS:[] ,
                        depNameA:[] ,
                        applys:[] ,
                        contractor:[] ,
                        firstparty:[] ,
                        arrivalDate:[] ,
                        signer:[] ,
                        contractNumber:[] ,
                        contract:[] ,
                        contractDate:[] ,
                        startDateAa:[] ,
                        enddateQp:[] ,
                        fujian:[] ,
                        contractMoney:[] ,
                        remarks:[] ,
                        invoiced:[] ,
        },
            //掩码配置
            maskConfig: {
                            contractor: {},
                            firstparty: {},
                            signer: {},
                            contract: {},
                },
            //定位属性
            locationScope: {
                },
            }
        },
        computed: {
            formOperates() {
                return this.setting.formOperates
            },


        },
        watch: {},
        created() {
            this.getFormById()
            if(this.dataForm.id == null || this.dataForm.id == '' && this.dataForm.id == undefined || this.dataForm.id == 0) {
                this.initDefaultData()
            }
            this.dataValueAll = JSON.parse(JSON.stringify(this.dataForm))
        },
        mounted() {},
        methods: {
            changeData(model, index) {
                this.childIndex = index
                let modelAll = model.split("-");
                let faceMode = "";
                for (let i = 0; i < modelAll.length; i++) {
                    faceMode += modelAll[i];
                }
                for (let key in this.interfaceRes) {
                    if (key != faceMode) {
                        let faceReList = this.interfaceRes[key]
                        for (let i = 0; i < faceReList.length; i++) {
                            if (faceReList[i].relationField == model) {
                                let options = 'get' + key + 'Options';
                                if(this[options]){
                                    this[options](true)
                                }
                                this.changeData(key, index)
                            }
                        }
                    }
                }
            },
            changeDataFormData(type, data, model,index,defaultValue) {
                if (type == 2) {
                    for (let i = 0; i < this.dataForm[data].length; i++) {
                        if (index == -1) {
                            this.dataForm[data][i][model] = defaultValue
                        } else if (index == i) {
                            this.dataForm[data][i][model] = defaultValue
                        }
                    }
                } else {
                    this.dataForm[data] = defaultValue
                }
            },
            dataAll(){
            },
            selfGetInfo(dataForm) {
                this.dataInfo(dataForm)
            },
            beforeSubmit(){
                const _data =this.dataList()
                return _data
            },
            selfInit() {
                this.dataAll()
            },
            getFormById() {
                getFormById("469143917162459013").then(res => {
                    this.dataForm.flowId = res.data&&res.data.flowId
                    // this.encode = res.data&&res.data.encode
                })
            },
            exist() {
                let isOk = true
                for (let key in this.tableRequiredData) {
                    if (this.dataForm[key] && Array.isArray(this.dataForm[key])) {
                        for (let i = 0; i < this.dataForm[key].length; i++) {
                            let item = this.dataForm[key][i]
                            inner: for (let id in item) {
                                let arr = this.tableRequiredData[key].filter(o => o.id === id) || []
                                if (!arr.length) continue inner
                                if (arr[0].required) {
                                    let msg = `${arr[0].name}不能为空`
                                    let boo = true
                                    if (arr[0].dataType === 'array') {
                                        boo = !this.jnpf.isEmptyArray(item[id])
                                    } else {
                                        boo = !this.jnpf.isEmpty(item[id])
                                    }
                                    if (!boo) {
                                        this.$message({
                                            message: msg,
                                            type: 'error',
                                            duration: 1000
                                        })
                                        isOk = false
                                        break
                                    }
                                }
                            }
                        }
                    }
                }
                    return isOk
                },
            clearData(){
                this.dataForm = JSON.parse(JSON.stringify(this.dataValueAll))


            },
            //初始化默认数据
            initDefaultData() {

            },
            openSelectDialog(key,value) {
                this.currTableConf=this.addTableConf[key + value]
                this.currVmodel=key
                this.selectDialogVisible = true
                this.$nextTick(() => {
                    this.$refs.selectDialog.init()
                })
            },
            addForSelect(data) {
                this.closeForSelect()
                for (let i = 0; i < data.length; i++) {
                    let t = data[i]
                    if(this['get'+this.currVmodel]){
                        this['get'+this.currVmodel](t,true)
                    }
                }
            },
            closeForSelect() {
                this.selectDialogVisible = false
            },
            dateTime(timeRule, timeType, timeTarget, timeValueData, dataValue) {
                let timeDataValue = null;
                let timeValue = Number(timeValueData)
                if (timeRule) {
                    if (timeType == 1) {
                        timeDataValue = timeValue
                    } else if (timeType == 2) {
                        timeDataValue = dataValue
                    } else if (timeType == 3) {
                        timeDataValue = new Date().getTime()
                    } else if (timeType == 4) {
                        let previousDate = '';
                        if (timeTarget == 1 || timeTarget == 2) {
                            previousDate = getDateDay(timeTarget, timeType, timeValue)
                            timeDataValue = new Date(previousDate).getTime()
                        } else if (timeTarget == 3) {
                            previousDate = getBeforeData(timeValue)
                            timeDataValue = new Date(previousDate).getTime()
                        } else {
                            timeDataValue = getBeforeTime(timeTarget, timeValue).getTime()
                        }
                    } else if (timeType == 5) {
                        let previousDate = '';
                        if (timeTarget == 1 || timeTarget == 2) {
                            previousDate = getDateDay(timeTarget, timeType, timeValue)
                            timeDataValue = new Date(previousDate).getTime()
                        } else if (timeTarget == 3) {
                            previousDate = getLaterData(timeValue)
                            timeDataValue = new Date(previousDate).getTime()
                        } else {
                            timeDataValue = getLaterTime(timeTarget, timeValue).getTime()
                        }
                    }
                }
                return timeDataValue;
            },
            time(timeRule, timeType, timeTarget, timeValue, formatType, dataValue) {
                let format = formatType == 'HH:mm' ? 'HH:mm:00' : formatType
                let timeDataValue = null
                if (timeRule) {
                    if (timeType == 1) {
                        timeDataValue = timeValue || '00:00:00'
                        if (timeDataValue.split(':').length == 3) {
                            timeDataValue = timeDataValue
                        } else {
                            timeDataValue = timeDataValue + ':00'
                        }
                    } else if (timeType == 2) {
                        timeDataValue = dataValue
                    } else if (timeType == 3) {
                        timeDataValue = this.jnpf.toDate(new Date(), format)
                    } else if (timeType == 4) {
                        let previousDate = '';
                        previousDate = getBeforeTime(timeTarget, timeValue)
                        timeDataValue = this.jnpf.toDate(previousDate, format)
                    } else if (timeType == 5) {
                        let previousDate = '';
                        previousDate = getLaterTime(timeTarget, timeValue)
                        timeDataValue = this.jnpf.toDate(previousDate, format)
                    }
                }
                return timeDataValue;
            },
            dataList(){
                var _data = this.dataForm;
                return _data;
            },
            dataInfo(dataAll){
                let _dataAll =dataAll
                this.dataForm = _dataAll
                this.dataAll()
                this.childIndex=-1
            },
        },
    }

</script>
